package com.foreknow.elmboot.controller;

import com.foreknow.elmboot.po.DeliveryAddress;
import com.foreknow.elmboot.po.OrderIdCart;
import com.foreknow.elmboot.service.OrderService;
import com.foreknow.elmboot.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/OrderController")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/listReadUserAddress")
    public List<DeliveryAddress> readAddress(Integer userId) throws Exception{
        return orderService.readAddress(userId);
    }

    @RequestMapping("/saveOrders")
    public int saveOrders(Integer userId, Integer businessId, Integer daId,Integer orderState) throws Exception {
        OrderIdCart orderIdCart = new OrderIdCart();
        orderIdCart.setUserId(userId);
        orderIdCart.setBusinessId(businessId);
        orderIdCart.setDaId(daId);
        orderIdCart.setOrderState(orderState);
        orderIdCart.setOrderDate(CommonUtil.getDateString());
        return orderService.saveOrders(orderIdCart);
    }
}
